package com.mySchool.controller;

import com.mySchool.anno.SysLog;
import com.mySchool.entity.*;
import com.mySchool.entity.DTO.BookInsertRequest;
import com.mySchool.entity.DTO.BookInsertResponse;
import com.mySchool.entity.DTO.ProvinceInsertRequest;
import com.mySchool.entity.PO.*;
import com.mySchool.service.*;
import io.swagger.v3.oas.annotations.*;
import lombok.extern.slf4j.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
* @author : Hinton
* @时间 : 2024/11/9 下午8:30
*/
@RestController
@Slf4j
@RequestMapping ("/province")
public class ProvinceController {

    @Autowired
    private ProvinceService provinceService;

    @PostMapping("/insert")
    @SysLog("新增省份")
    public Result insert(@RequestBody Request<ProvinceInsertRequest> insertRequest) {
        provinceService.insert( insertRequest.getParam());
        return Result.success();
    }

    @DeleteMapping
    @SysLog("删除省份")
    public Result delete(@RequestBody Request<List<Integer>> request) {
        provinceService.delete(request.getParam());
        return Result.success();
    }


    @GetMapping("/findById")
    @Operation(summary = "通过id找到省份")
    public ProvincePO findById(@RequestParam Long id) {
        return provinceService.findById(id);
    }


    @GetMapping("/findDetail")
    @Operation(summary = "通过名字找到省份下的信息")
    public Result findDetail(@RequestBody Request<String> request) {
        List<ProvincePO> list = provinceService.queryLower(request.getParam());
        if (list == null) {
            return Result.error("未找到该省份");
        }
        return Result.success(list);
    }



}
